<template>
	<!-- <view v-if="goods_info.goods_name">
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" style="height: 750rpx;">
			<swiper-item v-for="(item,i) in goods_info.pics" :key="i">
				<image :src="item.pics_big" @click="preview(i)" style="width: 100%;height: 100%"></image>
			</swiper-item>
		</swiper>
		<view class="p-2 pr-1 bg-white">
			<view class="my-2" style="color: #C00000;font-size: 18px;">￥{{goods_info.goods_price}}</view>
			<view class="flex justify-between">
				<view class="pr-2" style="font-size: 13px;">{{goods_info.goods_name}}</view>
				<view style="width: 120px;">
					<uni-fav :checked="favChecked" @click="favClick"></uni-fav>
				</view>
			</view>
			<view class="my-2 font-small text-muted">
				快递:免运费
			</view>
		</view>
		<view style="padding-bottom: 50px;" class="bg-white">
			<rich-text :nodes="goods_info.goods_introduce"></rich-text>
		</view>
		<view class="fixed-bottom" style="bottom: calc(var(--window-bottom))">
			<uni-goods-nav :fill="true" :options="options" :buttonGroup="buttonGroup" @click="onClick"
				@buttonClick="buttonClick" />
		</view>

		
	</view> -->
	<!-- <render-article-detail :content="data.content" :content-images="data.content_images"
		:ad-config="{ adpId, watchAdUniqueType }"></render-article-detail> -->
</template>

<script setup>
	import {
		onLoad
	} from "@dcloudio/uni-app"
	// import renderArticleDetail from "@/uni_modules/uni-cms-article/components/render-article-detail/index.vue";
	import {
		ref
	} from "vue"
	import {
		useCartStore
	} from "../../store"

	const cartStore = useCartStore()
	const goods_info = ref({})

	const options = ref([{
		icon: 'headphones',
		text: '客服'
	}, {
		icon: 'cart',
		text: '购物车',
		info: cartStore?.total || 0
	}])

	const buttonGroup = ref([{
			text: '加入购物车',
			backgroundColor: '#ff0000',
			color: '#fff'
		},
		{
			text: '立即购买',
			backgroundColor: '#ffa200',
			color: '#fff'
		}
	])

	const onClick = (e) => {
		if (e.index === 1) {
			uni.switchTab({
				url: "/pages/cart/cart"
			})
		}
	}

	const buttonClick = (e) => {
		if (e.index == 0) {
			const goods = {
				goods_id: goods_info.value.goods_id,
				goods_name: goods_info.value.goods_name,
				goods_price: goods_info.value.goods_price,
				goods_count: 1,
				goods_small_logo: goods_info.value.goods_small_logo,
				goods_state: true
			}
			cartStore.addToCart(goods)
			options.value[1].info = cartStore.total
		};
	}


	onLoad((options) => {
		const goods_id = options.goods_id
		getGoodsDetail(goods_id)

	})

	const favChecked = ref(false)
	const favClick = () => {
		favChecked.value = !favChecked.value
	}

	const preview = (i) => {
		uni.previewImage({
			current: i,
			urls: goods_info.value.pics.map(item => item.pics_big)
		})
	}

	const getGoodsDetail = async (goods_id) => {
		// const {
		// 	data: {
		// 		message
		// 	}
		// } = await uni.request({
		// 	url: "https://api-hmugo-web.itheima.net/api/public/v1/goods/detail",
		// 	method: "GET",
		// 	data: {
		// 		goods_id
		// 	}
		// })
		// message.goods_introduce = message.goods_introduce.replace(/<img/g, '<img style="display:block;" ').replace(
		// 	/webp/g, 'jpg')
		// goods_info.value = message

		const detail = uniCloud.importObject("Detail")
		const message = await detail.goodsDetail(goods_id)
		console.log(message);
	}
</script>

<style>

</style>